export class Item {
    id:number
    name:string
    amount:number
    box:string
}

export class EQUIP {
    body:Item
    hand:Item
    foot:Item
    head:Item
    nick:Item

    takeonEquip(item:Item){
        //判断物品装备位置
        //找到该位置是否有装备
        //item放到对应位置，返回该位置原来item或null
        this.updateProperty()
    }
    takeoffEquip(index:number){
        //找到对应位置item,返回item或null
        this.updateProperty()
    }
    //更新玩家属性
    updateProperty():void{

    }
}

//角色状态初始化
export class STATE  {
    temp = 0
    hp = 100
    full = 100
    moist = 100
    ps = 100
    san = 100

    changeState(state:STATE){
        this.temp += state.temp
        this.hp += state.hp
        this.full += state.full
        this.moist += state.moist
        this.ps += this.ps
        this.san += this.san
    }
}

//盒子
class Box{
    items:Item[]
    size:number

    //有无某件物品
    getItemIndex(id:number):number{
        for(var i=0; i< this.items.length; i++){
            var item:Item = this.items[i];
            if(item.id == id){
                return i
            }
        }
        return -1
    }
    //获取某件物品个数
    getItemCount(id:number):number{
        var index = this.getItemIndex(id)
        if(index == -1){
            return -1
        }else{
            return this.items[index].amount
        }
    }
    //添加物品
    puttems(items:Item[]):Item[]{
        var leftItems:Item[] = []
        for(var i=0; i< items.length; i++){
            var item:Item = items[i]
            //盒子中有无该物品
            var index = this.getItemIndex(item.id)
            if(index == -1){
                //无
                if(this.items.length >= this.size){
                    //没有空间
                    leftItems.push(item)
                }else{
                    this.items.push(item)
                }
            }else{
                //有
                this.items[index].amount += item.amount
            }
        }
        return leftItems
    }

    //取出物品
    popItems(items:Item[]):void{
        for(var i=0;i<items.length; i++){
            var item:Item = items[i]
            var index = this.getItemIndex(item.id)
            if(index == -1){
                //没有该物品
            }else{
                this.items[index].amount -= item.amount
                if(this.items[index].amount <= 0){
                    this.items.splice(index, 1)
                }
            }
        }
    }
}

//建筑
export class Building{
    id:number
    name:string
    level:number
    constructor(id:number,levl:number){
        this.id = id,
        this.name = "building"+id,
        this.level = levl
    }
    levelUp():void{
        this.level += 1
    }
}

//背包
export class Bag extends Box{

}

export class Build {
    makeTable:Building
    cooker:Building
    sleepPlace:Building
    bigBox:Building
    buildings:Building[]
    constructor(){
        this.makeTable = new Building(1,0)
        this.cooker = new Building(2,0)
        this.sleepPlace = new Building(3,0)
        this.bigBox = new Building(4,0)
        for(var i=0;i<4;i++){
            this.buildings[i] = new Building(i+1, 0)
        }
    }
    //升级建筑
    createBuild(id:number){
        //判断建筑等级是否最高
        //var level = this.buildings[(id-1)].level
    }
}
